/**
 * 
 */
package com.liusany.myshop.web.admin;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.liusany.myshop.bean.command.LoginCommand;

/**
 * 
 * @filename ：LoginController.java   
 * @description : 后台系统登录 真正的登录由shiro过滤器完成
 * @version ：   V 1.0
 * @author : liusany
 * @create : 2012-5-17 下午3:03:09  
 * @Copyright: Bmcok Corporation 2012    
 * 
 * Modification History:
 * 	Date			Author			Version			Description
 *--------------------------------------------------------------
 *2012-5-17 下午3:03:09
 */
@Controller
@RequestMapping(value = "/admin")
public final class LoginController {
      
	private static Logger logger = LoggerFactory.getLogger(LoginController.class);
	
	@RequestMapping(value = "/login", method = RequestMethod.GET)
	public String login() {
		logger.info("login......");
		return "admin/loginf";
	}

	@RequestMapping(value = "/login", method = RequestMethod.POST)
	public String fail(@RequestParam(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM) String userName, 
			@ModelAttribute LoginCommand command,Model model,HttpServletRequest request) {
		model.addAttribute(FormAuthenticationFilter.DEFAULT_USERNAME_PARAM, userName);
		logger.info("fail......");
		if(SecurityUtils.getSubject().isAuthenticated()){
			return "redirect:/admin/page/main";
		}
		return "admin/loginf";
	}

	

}
